/**
 * Created by gongxun on 16/11/18.
 */

var KwxMsgBoxLayer = KwxBaseLayer.extend({
    funcOk : null,
    objOk : null,
    funcClose : null,
    objClose : null,
    Panel_center : null,
    ctor : function () {
        this._super();
        this.loadCocostudio("res/ccs/KwxMsgBoxLayer.json");
        mo.gameHelper.fixIosText(this.ccsNode);
        this.Panel_center = mo.seekWidgetByName(this.ccsNode, "Panel_center");

        mo.seekWidgetByName(this.ccsNode, "Button_ok").addTouchEventListener(this.onTouchOk, this);

        mo.seekWidgetByName(this.ccsNode, "Panel_touch").addTouchEventListener(this.onTouchClose, this);

        mo.seekWidgetByName(this.ccsNode, "Button_close").addTouchEventListener(this.onTouchClose, this);

        mo.seekWidgetByName(this.ccsNode, "Button_cancel").addTouchEventListener(this.onTouchClose, this);
    },

    onEnter : function(){
        this._super();
        mo.soundHelper.playDialogOpen();
        this.showMsgBox();
    },

    showMsgBox : function(){
        this.showAction(this.Panel_center);
    },

    closeMsgBox : function(){
        if (this.closeAction(this.Panel_center)){
            //触发关闭函数
            return true;
        }
        return false;
    },

    onTouchOk : function(sender, type){
        if (mo.gameHelper.getIsTouchEndMenuClose(type)) {
            if (this.objOk){
                this.funcOk.call(this.objOk);
            }
            this.closeMsgBox();
        }
    },

    onTouchClose : function(sender, type){
        if (mo.gameHelper.getIsTouchEndMenuClose(type)) {
            if (this.closeMsgBox()){
                if (this.objClose){
                    this.funcClose.call(this.objClose);
                }
            }
        }
    },

    //设置文字信息
    setContent : function(content){
        mo.seekWidgetByName(this.ccsNode, "TextFix_content").setString(content);
    },

    //设置ok按钮文字
    setOkText : function(text){
        mo.gameHelper.setRootTitleText(mo.seekWidgetByName(this.ccsNode, "Button_ok"), text);
    },

    //只显示确定按钮
    setModeOnlyOk : function(){
        mo.seekWidgetByName(this.ccsNode, "Button_close").setEnabled(false);
        mo.seekWidgetByName(this.ccsNode, "Button_cancel").setVisible(false);
        mo.seekWidgetByName(this.ccsNode, "Panel_touch").setTouchEnabled(false);

        mo.seekWidgetByName(this.ccsNode, "Button_ok").setPositionX(0);
    },

    //显示确定按钮和取消按钮
    setModeOkAndCancel : function(){
        mo.seekWidgetByName(this.ccsNode, "Button_close").setEnabled(false);
    }
});


//显示文字
mo.showMsgDialogText = function(content){
    var kwxMsgBoxLayer = new KwxMsgBoxLayer();
    kwxMsgBoxLayer.setContent(content);
    kwxMsgBoxLayer.setModeOnlyOk();
    mo.sceneMainLayer.addChild(kwxMsgBoxLayer);
};

//触发确定操作
mo.showMsgDialogOk = function(content, callbackOk, objOk){
    var kwxMsgBoxLayer = new KwxMsgBoxLayer();
    kwxMsgBoxLayer.setContent(content);
    kwxMsgBoxLayer.objOk = objOk;
    kwxMsgBoxLayer.funcOk = callbackOk;
    kwxMsgBoxLayer.setModeOnlyOk();
    mo.sceneMainLayer.addChild(kwxMsgBoxLayer);
};


//触发确定和取消操作
mo.showMsgDialogOkAndCancel = function(content, callbackOk, objOk, callbackCancel, objCancel){
    var kwxMsgBoxLayer = new KwxMsgBoxLayer();
    kwxMsgBoxLayer.setContent(content);
    kwxMsgBoxLayer.objOk = objOk;
    kwxMsgBoxLayer.funcOk = callbackOk;
    kwxMsgBoxLayer.objClose = objCancel;
    kwxMsgBoxLayer.funcClose = callbackCancel;
    kwxMsgBoxLayer.setModeOkAndCancel();
    mo.sceneMainLayer.addChild(kwxMsgBoxLayer);
};